<?php
require_once("../../../config.inc.php");
$isReloadable = true;
require_once("../../../app/_inc/include.php");
require_once("../_inc/procFunction.php");

$errMsg = "";
if(isset($_REQUEST["reqtype"]) && $_REQUEST["reqtype"] == "delete"){
	$errMsg .= puAttrDel();
	$process_unit = sxREQUEST("process_unit");
	$alias = sxREQUEST("alias");
	$attribute = sxREQUEST("attribute");
	$entity = sxREQUEST("entity");
	$description = sxREQUEST("description");
	$read_only = (isset($_REQUEST["read_only"]))?"Y":"N";
	$note = sxREQUEST("note");
}else{
	$process_unit = sxREQ("pu");
	$alias = sxREQ("alias");
	$entity = sxREQ("ent");
	$attribute = sxREQ("attr");
	$description =  "";
	$read_only = "";
	$note =  "";
}
if($process_unit != ""){
	if($alias == ""){
		$errMsg .= _t("L'alias non &egrave; definito<br>");
	}
	if($entity == ""){
		$errMsg .= _t("L'entity non &egrave; definita<br>");
	}
	if($attribute == ""){
		$errMsg .= _t("L'attribute non &egrave; definito<br>");
	}
	if($errMsg == ""){
		$alias = addslashes(sxGPC(trim($_REQUEST["alias"])));
		$entity = addslashes(sxGPC(trim($_REQUEST["ent"])));
		$attribute = addslashes(sxGPC(trim($_REQUEST["attr"])));
		$sSQL = "SELECT ali.process_unit, ali.alias, ali.entity, a.attribute, pat.description,  pat.note, " .
				"    IFNULL(pat.read_only,ali.read_only) AS read_only, pat.attribute AS pat_attr " .
				" FROM pu_alias ali " .
				" INNER JOIN attribute a ON a.entity = ali.entity " .
				" LEFT JOIN pu_attribute pat ON pat.process_unit = ali.process_unit AND pat.alias = ali.alias " .
				"    AND pat.entity = ali.entity AND pat.attribute = a.attribute " .
				" WHERE ali.process_unit='$process_unit' AND ali.alias='$alias' " .
				" AND a.attribute = '$attribute'";
		$objSDAO->query($sSQL,"sel");
		if($row = $objSDAO->fetch("sel")){
			$description = $row["description"];
			$read_only = $row["read_only"];
			$note = $row["note"];
		}
	}	
}else{
	$errMsg .= _t("Il processo non &egrave; definito<br>");
}
//output HTML
$aOpz = array("tit2"=>_t("Visualizza attribute"), "isReloadable"=>$isReloadable);
echo(headerHTML($aOpz));
?>
<script language="JavaScript" type="text/javascript" src="../../_jsc/form.js"></script>
<?php
echo(bodyHTML($aOpz));
echo("<table width=\"100%\" cellpadding=\"03\" cellspacing=\"0\">\n<tr>\n<td>\n");
//form inserimento dati
echo("<form name=\"objFrm\" id=\"objFrm\" action=\"puAttrView.php\" method=\"POST\" enctype=\"multipart/form-data\">");
echo("<input type=\"hidden\" name=\"reqtype\" id=\"reqtype\" value=\"save\">");
echo("<input type=\"hidden\" name=\"xsn\" value=\"".XSN."\">");
echo("<input type=\"hidden\" name=\"process_unit\" id=\"process_unit\" value=\"$process_unit\">");
echo("<input type=\"hidden\" name=\"alias\" id=\"alias\" value=\"$alias\">");
echo("<input type=\"hidden\" name=\"entity\" id=\"entity\" value=\"$entity\">");
echo("<input type=\"hidden\" name=\"attribute\" id=\"attribute\" value=\"$attribute\">");
//output comandi
$aCmd = array(	"mod"=>array("pag"=>"puAttrMod.php?pu=$process_unit&alias=$alias&ent=$entity&attr=$attribute",
										"title"=>_t("modifica attribute"),
										"text"=>_t("modifica"),
										"perm"=>"viewmod"),
					"del"=>array("pag"=>"javascript:confirmDelete();",
										"title"=>_t("elimina attribute"),
										"text"=>_t("elimina"),
										"perm"=>"viewmod"),
					"back"=>array("pag"=>$objUser->getHistory(-1,false),
										"title"=>$objUser->getHistoryText(-1),
										"text"=>$objUser->getHistoryText(-1)
										)
					);
echo(commandsHTML($aCmd));	
echo("<table class=\"tabl01\" width=\"100%\" cellpadding=\"3\" cellspacing=\"2\" border='0'>\n");
echo("<tr>" .
			"<td class=\"titl01\" colspan='2'>"._t("Attributo")."</td>" .
		"</tr>\n");
echo("<tr>" .
			"<td class=\"labl01\" width=\"20%\">"._t("processo")."</td>" .
			"<td class=\"text01\">$process_unit</td>" .
		"</tr>\n");
echo("<tr>" .
			"<td class=\"labl01\">"._t("alias")."</td>" .
			"<td class=\"text01\">$alias</td>" .
		"</tr>\n");
echo("<tr>" .
			"<td class=\"labl01\">"._t("entit&egrave;")."</td>" .
			"<td class=\"text01\">$entity</td>" .
		"</tr>\n");
echo("<tr>" .
			"<td class=\"labl01\">"._t("attribute")."</td>" .
			"<td class=\"text01\">$attribute</td>" .
		"</tr>\n");
echo("<tr>" .
			"<td class=\"labl01\">"._t("description")."</td>" .
			"<td class=\"text01\">".sxHE($description)."</td>" .
		"</tr>\n");
if($read_only == "Y")
	$read_only = "Read-Only";
else
	$read_only = "";		
echo("<tr>" .
			"<td class=\"labl01\">"._t("sola lettura")."</td>" .
			"<td class=\"text01\">$read_only</td>" .
		"</tr>\n");
echo("<tr>" .
			"<td class=\"labl01\">"._t("note")."</td>" .
			"<td class=\"text01\"><pre class=\"text01\">".sxWW(sxHE($note))."</pre></td>" .
		"</tr>\n");
echo("</table>");

echo(commandsHTML($aCmd));

echo("</form>");
echo("</td>\n</tr>\n</table>\n");
echo(footerHTML());
exit();

function puAttrDel(){
 	global $objSDAO;
	$quote = "`";
	$errMsg = "";
	
	$process_unit = addslashes(sxGPC(trim($_REQUEST["process_unit"])));
	$alias = addslashes(sxGPC(trim($_REQUEST["alias"])));
	$entity = addslashes(sxGPC(trim($_REQUEST["entity"])));
	$attribute = addslashes(sxGPC(trim($_REQUEST["attribute"])));
	if($errMsg == ""){
		$sSQL = "DELETE FROM pu_attribute " .
				"WHERE process_unit='$process_unit' " .
				"AND entity='$entity'" .
				"AND attribute='$attribute'" .
				"AND alias='$alias'";	
		if($objSDAO->query($sSQL,"del",array("contOnErr"=>true))){
			//elimino i profili associati
			$_SESSION[USEROBJ]->reLoad();
			logRecord("500", _t("Eliminato l'attribute")." '$attribute' "._t("dal processo")." '$process_unit'");
			//serverRedir("puAttrList.php?pu=$process_unit&alias=$alias&xsn=".XSN);
			$url = $_SESSION[USEROBJ]->getHistory(-1, true);
			serverRedir($url);
		}else{
			$errMsg .= $sSQL."<br> - ".$objSDAO->error;
		}
	}
	return $errMsg;
} 
